<?php
/**
 * Created by PhpStorm.
 * User: liu
 * Date: 2018/5/4
 * Time: 17:50
 */

namespace app\admin\controller\sunfc;

use app\admin\controller\Base;
use app\index\model\lai;
use think\Db;

class Passenger extends Base
{
    public function index()
    {
        if (request()->isAjax()) {
            $dd_publish= Db::name('dd_publish')->where('type',1)->select();
            $page = input('page') ? input('page') : 1;
            $limit = input('limit') ? input('limit') : 10;
            $res=Db::name('dd_publish')->where('type',1)->page($page,$limit)->select();
            foreach ($res as $index=>$va){
                $res[$index]['create_time']=date('Y-m-d H:i:s',$va['create_time']);
                if ($res[$index]['type']==1){
                    $res[$index]['type']=='乘客';
                }else{
                    $res[$index]['type']=='司机';
                }
            }
            return json(['code' => 1, 'msg' => 'ok', 'count' => count($res), 'data' => $res]);
        } else {
            $count = Db::name('dd_publish')->count();
            $this->assign('count', $count);
            return $this->fetch();
        }
    }
    public function cases_search(){
        $dd_publish= Db::name('dd_publish')->where('type',1)->select();
        $page = input('page') ? input('page') : 1;
        $limit = input('limit') ? input('limit') : 10;
        $key = trim(input('uid'));
        $map = [];
        if (!$key){
            $this->error('暂无该数据');
        }else{
            $id = Db::name("dd_publish")->field("uid")->where("end_place",$key)->find();
            if(isset($id["uid"])){
                $map["iw_dd_publish.uid"] =  $id["uid"];
            }else{
                $this->error('查无此数据');
            }
        }
        if (input('type')==1) {
            $map["iw_dd_publish.type"] = input('type');
        }else{

        }
        $res=$dd_publish->where($map)->page($page,$limit)->select();
        foreach ($res as $index=>$va){
            $res[$index]['create_time']=date('Y-m-d H:i:s',$va['create_time']);
            if ($res[$index]['type']==1){
                $res[$index]['type']=='乘客';
            }else{
                $res[$index]['type']=='司机';
            }
        }
        $total = $res->page($page, $limit) ->where($map)->count();
        return json(['code' => 1, 'msg' => 'ok', 'total' => $total, 'data' => $res]);

    }
}